from django.shortcuts import render
from django.http import JsonResponse, HttpResponse
from django.shortcuts import get_object_or_404
from django.core import serializers
from django.template import loader
from django.contrib.auth import get_user_model

User = get_user_model()  # 用户模型

from .forms import *


# Create your views here.


def baidu_input(request):
    return render(request, 'business/input_mind.html', {})


def get_users(request):
    result = []
    values_list = ['username', 'gender']
    for p in User.objects.all().values_list(*values_list):
        print(p)
        choice = {k: v for k, v in User.gender_choice}[p[-1]]
        print(choice)
        # result.append(list(p[:-1]) + [choice])
        result.append({values_list[0]: p[0], values_list[1]: choice})
    res = {"users": result}
    print(res)
    return JsonResponse(res)


def test_captcha(request):
    form = CaptchaTestForm()
    test_str = "adb"
    if request.method == "POST" and request.POST:
        pass
    return render(request, 'business/captcha.html', locals())


def index(request):
    return render(request, 'business/captcha.html', locals())
